package com.neusoft.elm.service.impl;

import com.neusoft.elm.DBUtil;
import com.neusoft.elm.dao.CartDao;
import com.neusoft.elm.dao.impl.CartDaoImpl;
import com.neusoft.elm.po.Cart;
import com.neusoft.elm.service.CartService;

import java.util.List;

public class CartServiceImpl implements CartService {
CartDao cartDao=new CartDaoImpl();
    @Override
    public List<Cart> listCart(Cart cart) throws Exception {
        try {
            DBUtil.getConnection();
            List<Cart> list = cartDao.listCart(cart);
            return list;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            DBUtil.close();
        }


    }

    @Override
    public int saveCart(Cart cart) throws Exception {
        try {
            DBUtil.getConnection();
            int n=cartDao.saveCart(cart);
            return n;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            DBUtil.close();
        }


    }

    @Override
    public int removeCart(Cart cart) throws Exception {
        try {
            DBUtil.getConnection();
            int n=cartDao.removeCart(cart);
            return n;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            DBUtil.close();
        }


    }

    @Override
    public int updateCart(Cart cart) throws Exception {
        try {
            DBUtil.getConnection();
            int n=cartDao.updateCart(cart);
            return n;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            DBUtil.close();
        }


    }
}
